package ar.com.hakasoft.utils
import java.sql.Timestamp
import java.text.SimpleDateFormat

class DateUtil {

	static toString(aDate) {
		if (aDate) {
			return new SimpleDateFormat("dd/MM/yyyy").format(aDate)
		} else {
			return null
		}
	} 

	static toString(aDate, full) {
		if (aDate) {
			def dateFormat
			if (full) {
				dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm")
			} else {
				dateFormat = new SimpleDateFormat("dd/MM/yyyy")
			}
			return dateFormat.format(aDate)
		} else {
			return null
		}
	}

	static toDate(aString) {
		if (aString) {
			return new SimpleDateFormat("dd/MM/yyyy").parse(aString)
		} else {
			return null
		}
	}
	
	static convertToCal(String fecha){
		Calendar calendarMinimo = Calendar.getInstance()
		def fechaParseada = fecha.split()
		calendarMinimo.set(fechaParseada[2].toInteger(), fechaParseada[1].toInteger()-1, fechaParseada[0].toInteger(), 0, 0, 0)
		return calendarMinimo
	}
	
	static isSameDayOf(def date1, def cal2){
		if (date1 == null){
			return false;
		}
		if (cal2 == null){
			return false;
		}
		Calendar cal1 = Calendar.getInstance()
		cal1.setTime(date1)
		return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
	}
	
	static getSameDayOf(Date date1, Date date2){
		if (date1 == null){
			return false;
		}
		Calendar cal1 = Calendar.getInstance()
		Calendar cal2 = Calendar.getInstance()
		cal1.setTime(date1)
		cal2.setTime(date2)
		return cal1.get(Calendar.YEAR) == cal2.get(Calendar.YEAR) && cal1.get(Calendar.DAY_OF_YEAR) == cal2.get(Calendar.DAY_OF_YEAR)
	}
	 

}
